@scrider/formatter 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/NOTICE +52 -0
- package/README.md +123 -0
- package/dist/index.cjs +4946 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1658 -0
- package/dist/index.d.ts +1658 -0
- package/dist/index.js +4844 -0
- package/dist/index.js.map +1 -0
- package/package.json +109 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025-2026 Pavel Sukharev
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
@scrider/formatter
|
|
2
|
+
Copyright (c) 2025-2026 Pavel Sukharev
|
|
3
|
+
|
|
4
|
+
This product is licensed under the MIT License.
|
|
5
|
+
See the LICENSE file for details.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Runtime Dependencies
|
|
9
|
+
====================
|
|
10
|
+
|
|
11
|
+
1. @scrider/delta
|
|
12
|
+
Copyright (c) 2025-2026 Pavel Sukharev
|
|
13
|
+
Licensed under the MIT License
|
|
14
|
+
https://github.com/scrider-apps/scrider-delta
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
Optional Peer Dependencies (not bundled)
|
|
18
|
+
========================================
|
|
19
|
+
|
|
20
|
+
The following packages are optional peer dependencies used at runtime
|
|
21
|
+
only when the corresponding features are invoked. They are NOT included
|
|
22
|
+
in the distributed bundle.
|
|
23
|
+
|
|
24
|
+
2. jsdom
|
|
25
|
+
Copyright (c) 2010 Elijah Insua
|
|
26
|
+
Licensed under the MIT License
|
|
27
|
+
https://github.com/jsdom/jsdom
|
|
28
|
+
|
|
29
|
+
3. unified
|
|
30
|
+
Copyright (c) Titus Wormer
|
|
31
|
+
Licensed under the MIT License
|
|
32
|
+
https://github.com/unifiedjs/unified
|
|
33
|
+
|
|
34
|
+
4. remark-parse
|
|
35
|
+
Copyright (c) Titus Wormer
|
|
36
|
+
Licensed under the MIT License
|
|
37
|
+
https://github.com/remarkjs/remark
|
|
38
|
+
|
|
39
|
+
5. remark-stringify
|
|
40
|
+
Copyright (c) Titus Wormer
|
|
41
|
+
Licensed under the MIT License
|
|
42
|
+
https://github.com/remarkjs/remark
|
|
43
|
+
|
|
44
|
+
6. remark-gfm
|
|
45
|
+
Copyright (c) Titus Wormer
|
|
46
|
+
Licensed under the MIT License
|
|
47
|
+
https://github.com/remarkjs/remark-gfm
|
|
48
|
+
|
|
49
|
+
7. remark-math
|
|
50
|
+
Copyright (c) Junyoung Choi, Titus Wormer
|
|
51
|
+
Licensed under the MIT License
|
|
52
|
+
https://github.com/remarkjs/remark-math
|
package/README.md
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# @scrider/formatter
|
|
2
|
+
|
|
3
|
+
Schema, conversion and block handlers for rich-text content. HTML, Markdown, sanitization.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`@scrider/formatter` is the processing layer of the [Scrider](https://github.com/scrider-apps) ecosystem. It provides format definitions (schema), HTML/Markdown conversion, sanitization, and extensible block handlers — all as pure, stateless functions on top of [`@scrider/delta`](https://github.com/scrider-apps/scrider-delta). Strict TypeScript, zero runtime dependencies beyond `@scrider/delta`.
|
|
8
|
+
|
|
9
|
+
## Key Features
|
|
10
|
+
|
|
11
|
+
- **Schema** — extensible format registry (31 built-in formats: inline, block, embed)
|
|
12
|
+
- **HTML conversion** — `deltaToHtml()` / `htmlToDelta()` with DOM adapters (browser + Node.js)
|
|
13
|
+
- **Markdown conversion** — `deltaToMarkdown()` / `markdownToDelta()` (GFM, math, footnotes)
|
|
14
|
+
- **Block handlers** — tables, footnotes, alerts, columns, inline-box
|
|
15
|
+
- **Sanitization** — `sanitizeDelta()`, `validateDelta()`, `normalizeDelta()`
|
|
16
|
+
- **Dual format** — ESM + CJS builds
|
|
17
|
+
- **Strict TypeScript** — full type safety, discriminated unions
|
|
18
|
+
- **Stateless** — pure functions, no DOM coupling, works in browser, Node.js, Web Workers
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @scrider/formatter @scrider/delta
|
|
24
|
+
# or
|
|
25
|
+
pnpm add @scrider/formatter @scrider/delta
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Optional peer dependencies (install only what you need):
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# Node.js HTML conversion (server-side)
|
|
32
|
+
pnpm add jsdom
|
|
33
|
+
|
|
34
|
+
# Markdown conversion
|
|
35
|
+
pnpm add unified remark-parse remark-stringify remark-gfm
|
|
36
|
+
|
|
37
|
+
# Math in Markdown
|
|
38
|
+
pnpm add remark-math
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Quick Start
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { Delta } from '@scrider/formatter';
|
|
45
|
+
import { deltaToHtml, htmlToDelta, createDefaultRegistry } from '@scrider/formatter';
|
|
46
|
+
|
|
47
|
+
// Create a document
|
|
48
|
+
const doc = new Delta()
|
|
49
|
+
.insert('Hello', { bold: true })
|
|
50
|
+
.insert(' world\n');
|
|
51
|
+
|
|
52
|
+
// Convert to HTML
|
|
53
|
+
const registry = createDefaultRegistry();
|
|
54
|
+
const html = deltaToHtml(doc, { registry });
|
|
55
|
+
// → '<p><strong>Hello</strong> world</p>'
|
|
56
|
+
|
|
57
|
+
// Convert back to Delta
|
|
58
|
+
const delta = htmlToDelta(html, { registry });
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## API
|
|
62
|
+
|
|
63
|
+
### Schema
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { Registry, createDefaultRegistry, BlockHandlerRegistry } from '@scrider/formatter';
|
|
67
|
+
|
|
68
|
+
const registry = createDefaultRegistry(); // 31 built-in formats
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### HTML Conversion
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { deltaToHtml, htmlToDelta } from '@scrider/formatter';
|
|
75
|
+
|
|
76
|
+
deltaToHtml(delta, { registry }) // Delta → HTML string
|
|
77
|
+
htmlToDelta(html, { registry }) // HTML string → Delta
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Markdown Conversion
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
import { deltaToMarkdown, markdownToDelta } from '@scrider/formatter';
|
|
84
|
+
|
|
85
|
+
deltaToMarkdown(delta, options?) // Delta → Markdown string
|
|
86
|
+
await markdownToDelta(markdown, options?) // Markdown string → Delta (async)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Sanitization
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
import { sanitizeDelta, validateDelta, normalizeDelta } from '@scrider/formatter';
|
|
93
|
+
|
|
94
|
+
sanitizeDelta(delta, { registry }) // Remove unknown formats
|
|
95
|
+
validateDelta(delta, { registry }) // Check validity (boolean)
|
|
96
|
+
normalizeDelta(delta) // Normalize operations
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Block Handlers
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import {
|
|
103
|
+
tableBlockHandler,
|
|
104
|
+
footnotesBlockHandler,
|
|
105
|
+
alertBlockHandler,
|
|
106
|
+
columnsBlockHandler,
|
|
107
|
+
boxBlockHandler,
|
|
108
|
+
} from '@scrider/formatter';
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Ecosystem
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
@scrider/delta Core — Delta, OT (0 deps)
|
|
115
|
+
↑
|
|
116
|
+
@scrider/formatter ← you are here (Schema + Conversion)
|
|
117
|
+
↑
|
|
118
|
+
@scrider/editor React WYSIWYG Component (planned)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## License
|
|
122
|
+
|
|
123
|
+
[MIT](./LICENSE)
|